/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Servlet;

import JavaBeans.User;
import classes.Reports;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Brian
 */
public class stocktype extends HttpServlet {

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, SQLException {
        response.setContentType("text/html;charset=UTF-8");

        try {
            
            HttpSession ss = request.getSession(true);
            User user = (User)ss.getAttribute("user");
            String stock=request.getParameter("stock");
            
            Reports.getConnection("SELECT T.StockID, S.CompanyName, O.PricePerShare, O.NumShares, O.Order1, MAX(O.DateTime) As Recent FROM `brchung`.`stock` S, `brchung`.`order1` O, `brchung`.`trade` T, `brchung`.`account` A WHERE A.Id = T.AccountId AND T.StockId=S.StockSymbol AND S.Type='"+stock +"' AND A.Client='"+ user.getSsn() +"' GROUP By T.StockID ORDER BY O.DateTime Limit 1;");
            ArrayList<String[]> rs=Reports.getResults(1,2,3,4,5,6);
            request.setAttribute("rs", rs);
            request.setAttribute("stocktype", "abc");
            request.getRequestDispatcher("index.jsp").forward(request, response);
            
        } finally {            
            
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(salesreport.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(salesreport.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
